import prisma from '@/server/lib/prisma';
import { verifyToken } from '@/server/lib/jwt';

export default defineEventHandler(async (event) => {
  try {
    const headers = getHeaders(event);
    const authorization = headers['authorization'] as string;
    const token = authorization.split(' ')[1];
    const decoded: any = verifyToken(token);
    const username = decoded.username;
    const user = await prisma.sys_user.findFirst({
      where: {
        userName: username
      },
    })

    return {
      code: 200,
      data: user
    }
  } catch (e) {
    throw e;
  } finally {
    await prisma.$disconnect(); // 关闭连接
  }
})